﻿using System;
using System.Collections.Generic;
using System.Linq;

public class Class3
{
    delegate int del(int i,string aa);
    delegate string setText(string text);
    public delegate TResult Func<T, TResult>(T arg);
    static void Main(string[] args)
    {

        string aa = "";
        del cc =
          (int x,string str) =>
          {
              aa = "cc";
              int c = 10;
              double d = 0;
              if (c * x % 10 == 0)
              {
                  return x / 10;
              }
              else
              {
                  return x / 10 + 1; ;
              }
              
          };

        int[] scores = { 90, 71, 82, 93, 75, 82 };

        // The call to Count forces iteration of the source
        int highScoreCount = scores.Where(n => n > 80).Count();

        scores.Where(sgwg => sgwg > 80).Count();
        long l10aa = Convert.ToInt64("15",16);
        string s = Convert.ToString(l10aa, 2);

        



       int abc = cc(30,"2");
        Console.WriteLine(abc);
        Console.WriteLine(aa);
        var result =
            from score in scores
            where score > 10
            select new { abc=score  };


        string[] scoresArray = { "90", null, "82", "93", "75", "82" };
       
        var cf = from score in scoresArray 
                 where score != null 
                 select new { abc = score, a2 = score };

        foreach (var item in cf)
        {
            Console.WriteLine(item);
        }


        
        Console.WriteLine(result.Count());

        foreach (var item in result)
        {
            Console.WriteLine(item.abc);
        }

        TotalsByGradeLevel(StudentClass.students);
        Console.ReadKey();
    }

    private static void TotalsByGradeLevel(List<StudentClass.Student> students)
    {
        
        var categories =
        from student in students 
        group student by student.Year into studentGroup
        select new { GradeLevel = studentGroup.Key, TotalScore = studentGroup.Sum(s => s.ExamScores.Sum()) };

        
       
        var aaa11 =
            from sgwg in students
            where sgwg.ID == 1200 && sgwg.Year== StudentClass.GradeLevel.FirstYear
            select new {Name=sgwg.FirstName+sgwg.LastName,Id=sgwg.ID};

        
        foreach (var cat in categories)
        {
            
            Console.WriteLine("Key = {0} Sum = {1}", cat.GradeLevel, cat.TotalScore);
        }
    }

   




    public class StudentClass
    {
        #region data

        public enum GradeLevel { FirstYear = 1, SecondYear, ThirdYear, FourthYear };
        public class Student
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public int ID { get; set; }
            public GradeLevel Year;
            public List<int> ExamScores;
        }
        public static List<Student> students = new List<Student>
    {
        new Student {FirstName = "Terry", LastName = "Adams", ID = 120, Year = GradeLevel.SecondYear, ExamScores = new List<int>{ 99, 82, 81, 79}},
        new Student {FirstName = "Fadi", LastName = "Fakhouri", ID = 116, Year = GradeLevel.ThirdYear,ExamScores = new List<int>{ 99, 86, 90, 94}},
        new Student {FirstName = "Hanying", LastName = "Feng", ID = 117, Year = GradeLevel.FirstYear, ExamScores = new List<int>{ 93, 92, 80, 87}},
        new Student {FirstName = "Cesar", LastName = "Garcia", ID = 114, Year = GradeLevel.FourthYear,ExamScores = new List<int>{ 97, 89, 85, 82}},
        new Student {FirstName = "Debra", LastName = "Garcia", ID = 115, Year = GradeLevel.ThirdYear, ExamScores = new List<int>{ 35, 72, 91, 70}},
        new Student {FirstName = "Hugo", LastName = "Garcia", ID = 118, Year = GradeLevel.SecondYear, ExamScores = new List<int>{ 92, 90, 83, 78}},
        new Student {FirstName = "Sven", LastName = "Mortensen", ID = 113, Year = GradeLevel.FirstYear, ExamScores = new List<int>{ 88, 94, 65, 91}},
        new Student {FirstName = "Claire", LastName = "O'Donnell", ID = 112, Year = GradeLevel.FourthYear, ExamScores = new List<int>{ 75, 84, 91, 39}},
        new Student {FirstName = "Svetlana", LastName = "Omelchenko", ID = 111, Year = GradeLevel.SecondYear, ExamScores = new List<int>{ 97, 92, 81, 60}},
        new Student {FirstName = "Lance", LastName = "Tucker", ID = 119, Year = GradeLevel.ThirdYear, ExamScores = new List<int>{ 68, 79, 88, 92}},
        new Student {FirstName = "Michael", LastName = "Tucker", ID = 122, Year = GradeLevel.FirstYear, ExamScores = new List<int>{ 94, 92, 91, 91}},
        new Student {FirstName = "Eugene", LastName = "Zabokritski", ID = 121, Year = GradeLevel.FourthYear, ExamScores = new List<int>{ 96, 85, 91, 60}}
    };
        #endregion
    }
    /*
         Outputs: 
         Key = SecondYear Sum = 1014
         Key = ThirdYear Sum = 964
         Key = FirstYear Sum = 1058
         Key = FourthYear Sum = 974
    */
}


